class preorder_and_inorder_creat_binary_tree {

    static class TreeNode{
        public int value;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int value) {
            this.value = value;
        }
    }

    public int indexPre;
    public TreeNode buildTree(int[] preorder, int[] inorder) {
     return buildTreeChild(preorder,inorder,0,inorder.length-1);
    }
    public TreeNode buildTreeChild(int[] preorder,int[] inorder,int begin,int end){
        if(begin>end)
      return null;
      int j=0;
      TreeNode root=new TreeNode(preorder[indexPre]);
      for(j=begin;j<=end;j++){
        if(preorder[indexPre]==inorder[j]) break;
      }

      indexPre++;
       root.left = buildTreeChild(preorder,inorder,begin,j-1);
      root.right = buildTreeChild(preorder,inorder,j+1,end);
    
    return root;

    }
}